using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class PregledNaIgraci : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Proekt.mdb;"; //postavuvame "adresa" do bazata
        OleDbConnection conn = new OleDbConnection(conString);

        conn.Open();

        string select = "SELECT IME, BOJA, KUKI, HOTEL FROM POLINJA WHERE IGRACID = ?";
        OleDbCommand select_pole = new OleDbCommand(select, conn);
        select_pole.Parameters.AddWithValue("?", ListBox1.SelectedValue);
        //OleDbDataReader reader = select_pole.ExecuteReader();

        OleDbDataAdapter temp = new OleDbDataAdapter(select_pole);

        DataTable tabela = new DataTable();
        temp.Fill(tabela);

        GridView1.DataSource = tabela;
        GridView1.DataBind();

        string select1 = "SELECT SUM(KUKI) AS K FROM POLINJA WHERE IGRACID = ?";
        OleDbCommand select_broj = new OleDbCommand(select1, conn);
        select_broj.Parameters.AddWithValue("?", ListBox1.SelectedValue);
        Label4.Text = "Igracot " + ListBox1.SelectedItem + " poseduva vkupno " + select_broj.ExecuteScalar().ToString() + " kuki";

        string select2 = "SELECT SUM(HOTEL) AS H FROM POLINJA WHERE IGRACID = ?";
        OleDbCommand select_broj2 = new OleDbCommand(select2, conn);
        select_broj2.Parameters.AddWithValue("?", ListBox1.SelectedValue);
        Label5.Text = "Igracot "+ListBox1.SelectedItem+" poseduva vkupno " + select_broj2.ExecuteScalar().ToString()+" hoteli";

        conn.Close();

        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Proekt.mdb;"; //postavuvame "adresa" do bazata
        OleDbConnection conn = new OleDbConnection(conString);

        conn.Open();

        object temp = ListBox1.SelectedValue;

        string select = "UPDATE POLINJA SET IGRACID = NULL, KUKI = 0, HOTEL= 0 WHERE IGRACID = ?";
        OleDbCommand select_pole = new OleDbCommand(select, conn);
        select_pole.Parameters.AddWithValue("?", temp);
        select_pole.ExecuteNonQuery();

        string delete = "DELETE FROM IGRACI WHERE ID = ?";
        OleDbCommand delete_igrac = new OleDbCommand(delete, conn);
        delete_igrac.Parameters.AddWithValue("?", temp);
        delete_igrac.ExecuteNonQuery();

        conn.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("DodadiIgrac.aspx");
    }
}
